package h0729;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.StringJoiner;

/**
  * @description 寻找身高相近的小朋友
  * @author 不知名帅哥
  * @date 2024/7/29 17:36
  * @version 1.0
*/
public class FindHeightLikeMe {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h= sc.nextInt();
        int n=sc.nextInt();
        Integer[] heights= new Integer[n];
        for (int i = 0; i < n; i++) {
            heights[i]=sc.nextInt();
        }
        Arrays.sort(heights, (o1, o2) -> {
            int a = Math.abs(o1 - h);
            int b = Math.abs(o2 - h);
            if (a!=b){
                return Integer.compare(a,b);
            }else {
                return Integer.compare(o1,o2);
            }
        });
        StringJoiner joiner=new StringJoiner(" ");
        for (Integer height : heights) {
            joiner.add(height+"");
        }
        System.out.println(joiner);
    }
}
